FROM nginx:1.20.1

MAINTAINER phperhuan

# 创建基础信息
RUN mkdir -p /www \
	&& mkdir -p /wwwlogs \

	# 更新nginx.conf
	&& rm -rf /etc/nginx/nginx.conf \
	&& echo "user nginx;" >> /etc/nginx/nginx.conf \
	&& echo "worker_processes auto;" >> /etc/nginx/nginx.conf \
	&& echo "" >> /etc/nginx/nginx.conf \
	&& echo "error_log /var/log/nginx/error.log notice;" >> /etc/nginx/nginx.conf \
	&& echo "pid /var/run/nginx.pid;" >> /etc/nginx/nginx.conf \
	&& echo "" >> /etc/nginx/nginx.conf \
	&& echo "events {" >> /etc/nginx/nginx.conf \
	&& echo "    worker_connections 1024;" >> /etc/nginx/nginx.conf \
	&& echo "}" >> /etc/nginx/nginx.conf \
	&& echo "" >> /etc/nginx/nginx.conf \
	&& echo "http {" >> /etc/nginx/nginx.conf \
	&& echo "    include /etc/nginx/mime.types;" >> /etc/nginx/nginx.conf \
	&& echo "    default_type application/octet-stream;" >> /etc/nginx/nginx.conf \
	&& echo "" >> /etc/nginx/nginx.conf \
	&& echo "    log_format main '\$remote_addr - \$remote_user [\$time_local] \"\$request\" '" >> /etc/nginx/nginx.conf \
	&& echo "                    '\$status \$body_bytes_sent \"\$http_referer\" '" >> /etc/nginx/nginx.conf \
	&& echo "                    '\"\$http_user_agent\" \"\$http_x_forwarded_for\"';" >> /etc/nginx/nginx.conf \
	&& echo "" >> /etc/nginx/nginx.conf \
	&& echo "    access_log /wwwlogs/access.log;" >> /etc/nginx/nginx.conf \
	&& echo "    error_log /wwwlogs/error.log;" >> /etc/nginx/nginx.conf \
	&& echo "" >> /etc/nginx/nginx.conf \
	&& echo "    sendfile on;" >> /etc/nginx/nginx.conf \
	&& echo "    #tcp_nopush on;" >> /etc/nginx/nginx.conf \
	&& echo "" >> /etc/nginx/nginx.conf \
	&& echo "    keepalive_timeout 65;" >> /etc/nginx/nginx.conf \
	&& echo "" >> /etc/nginx/nginx.conf \
	&& echo "    #gzip on;" >> /etc/nginx/nginx.conf \
	&& echo "" >> /etc/nginx/nginx.conf \
	&& echo "    include /etc/nginx/conf.d/*.conf;" >> /etc/nginx/nginx.conf \
	&& echo "}" >> /etc/nginx/nginx.conf \

	# 写入php73.fpm
	&& echo "# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000" >> /etc/nginx/conf.d/php73.fpm \
	&& echo "#" >> /etc/nginx/conf.d/php73.fpm \
	&& echo "location ~ \.php$ {" >> /etc/nginx/conf.d/php73.fpm \
	&& echo "    fastcgi_pass   172.17.0.4:9000;" >> /etc/nginx/conf.d/php73.fpm \
	&& echo "    fastcgi_index  index.php;" >> /etc/nginx/conf.d/php73.fpm \
	&& echo "    fastcgi_param  SCRIPT_FILENAME \$document_root\$fastcgi_script_name;" >> /etc/nginx/conf.d/php73.fpm \
	&& echo "    include        fastcgi_params;" >> /etc/nginx/conf.d/php73.fpm \
	&& echo "}" >> /etc/nginx/conf.d/php73.fpm \

	# 更新default.conf
	&& rm -rf /etc/nginx/conf.d/default.conf \
	&& echo "server {" >> /etc/nginx/conf.d/default.conf \
	&& echo "    listen 80;" >> /etc/nginx/conf.d/default.conf \
	&& echo "    listen [::]:80;" >> /etc/nginx/conf.d/default.conf \
	&& echo "    server_name localhost;" >> /etc/nginx/conf.d/default.conf \
	&& echo "    root /www/default;" >> /etc/nginx/conf.d/default.conf \
	&& echo "" >> /etc/nginx/conf.d/default.conf \
	&& echo "    access_log /wwwlogs/default_access.log;" >> /etc/nginx/conf.d/default.conf \
	&& echo "    error_log /wwwlogs/default_error.log;" >> /etc/nginx/conf.d/default.conf \
	&& echo "" >> /etc/nginx/conf.d/default.conf \
	&& echo "    location / {" >> /etc/nginx/conf.d/default.conf \
	&& echo "        index index.html index.htm index.php;" >> /etc/nginx/conf.d/default.conf \
	&& echo "        try_files \$uri \$uri/ /index.php?\$query_string;" >> /etc/nginx/conf.d/default.conf \
	&& echo "    }" >> /etc/nginx/conf.d/default.conf \
	&& echo "" >> /etc/nginx/conf.d/default.conf \
	&& echo "    include conf.d/php73.fpm;" >> /etc/nginx/conf.d/default.conf \
	&& echo "}" >> /etc/nginx/conf.d/default.conf \

	# 写入www.dockertest.com
	&& echo "server {" >> /etc/nginx/conf.d/www.dockertest.com.conf \
	&& echo "    server_name www.dockertest.com;" >> /etc/nginx/conf.d/www.dockertest.com.conf \
	&& echo "    root /www/dockertest;" >> /etc/nginx/conf.d/www.dockertest.com.conf \
	&& echo "" >> /etc/nginx/conf.d/www.dockertest.com.conf \
	&& echo "    access_log /wwwlogs/dockertest_access.log;" >> /etc/nginx/conf.d/www.dockertest.com.conf \
	&& echo "    error_log /wwwlogs/dockertest_access.log;" >> /etc/nginx/conf.d/www.dockertest.com.conf \
	&& echo "" >> /etc/nginx/conf.d/www.dockertest.com.conf \
	&& echo "    location / {" >> /etc/nginx/conf.d/www.dockertest.com.conf \
	&& echo "        index index.html index.htm index.php;" >> /etc/nginx/conf.d/www.dockertest.com.conf \
	&& echo "        try_files \$uri \$uri/ /index.php?\$query_string;" >> /etc/nginx/conf.d/www.dockertest.com.conf \
	&& echo "    }" >> /etc/nginx/conf.d/www.dockertest.com.conf \
	&& echo "" >> /etc/nginx/conf.d/www.dockertest.com.conf \
	&& echo "    include conf.d/php73.fpm;" >> /etc/nginx/conf.d/www.dockertest.com.conf \
	&& echo "}" >> /etc/nginx/conf.d/www.dockertest.com.conf \